package com.kang.controller;

import com.kang.service.OssOperService;
import com.kang.util.WebResponse;
import com.kang.vo.OssVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "Oss文件的操作")
@RestController
@RequestMapping("/oss/oper")
@Slf4j
public class OssOperController {

    @Autowired
    private OssOperService ossOperService;

    @ApiOperation("获取oss所有视频文件")
    @GetMapping("getOssShiPinList/{page}/{limit}")
    public WebResponse getOssShiPinList(@PathVariable("page") Integer page,@PathVariable("limit") Integer limit) {
        try {
            return WebResponse.resSuccess("获取oss所有视频文件成功",ossOperService.getOssShiPinList(page,limit));
        } catch (Exception ex) {
            log.error("获取oss所有视频文件失败",ex);
            return WebResponse.resFail("获取oss所有视频文件失败",null);
        }
    }

    @ApiOperation("获取oss所有图片文件")
    @GetMapping("getOssTuPianList/{page}/{limit}")
    public WebResponse getOssTuPianList(@PathVariable("page") Integer page,@PathVariable("limit") Integer limit) {
        try {
            return WebResponse.resSuccess("获取oss所有图片文件成功",ossOperService.getOssTuPianList(page,limit));
        } catch (Exception ex) {
            log.error("获取oss所有图片文件失败",ex);
            return WebResponse.resFail("获取oss所有图片文件失败",null);
        }
    }

    @ApiOperation("删除Oss中某个图片")
    @PostMapping("deleteOssTuPianLis")
    public WebResponse deleteOssTuPianLis(@RequestBody OssVo ossVo) {
        try {
            return WebResponse.resSuccess("删除Oss中某个图片成功",ossOperService.deleteOssTuPianLis(ossVo.getFileName()));
        } catch (Exception ex) {
            log.error("删除Oss中某个图片失败",ex);
            return WebResponse.resFail("删除Oss中某个图片失败",null);
        }
    }

    @ApiOperation("删除Oss中某个视频")
    @PostMapping("deleteOssShiPinLis")
    public WebResponse deleteOssShiPinLis(String fileName) {
        try {
            return WebResponse.resSuccess("删除Oss中某个视频成功",ossOperService.deleteOssShiPinLis(fileName));
        } catch (Exception ex) {
            log.error("删除Oss中某个视频失败",ex);
            return WebResponse.resFail("删除Oss中某个视频失败",null);
        }
    }



}
